﻿using Module_Debug.Hardware;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Threading;
using System.Windows.Forms;


namespace Module_Debug.Visionox_Gamma
{
    public partial class RM6D010_Gamma : Form
    {
        CaSDK CaSDKObj = new CaSDK();
        CRC16 CRCData = new CRC16();
        Gamma_Addr GAMMAs = new Gamma_Addr();

        private bool Listening = false;//是否没有执行完invoke相关操作   
        private bool IClosing = false;//是否正在关闭串口，执行Application.DoEvents，并阻止再次invoke 

        private List<byte> buffer = new List<byte>(2048);//默认分配1/16页内存，并始终限制不允许超过

        private double[,] D_lums;//目标值-单色
        private double[] D_lum;//目标值-白色
        private double D_x, D_y;
        private double lum_off, x_off, y_off;
        private int index = 0;
        private int flag1 = 1; //lum
        private int flag2 = 1; //x
        private int flag3 = 1; //y
        private byte[] Send_buf = new byte[1];
        private byte[] Rec_tmp = new byte[1];
        public byte RM010_0XFE_XX = 0;
        private static bool Gamma_adjust_timeout_flag = false;
        private int adjust_Rnum = 0;
        private int adjust_Gnum = 0;
        private int adjust_Bnum = 0;
        public int adjust_l = 0;
        public int adjust_x = 0;
        public int adjust_y = 0;
        private int step_l = 1;
        //private int step_m = 5;
        private int step_h = 12;

        //监听RM6D010挂载
        frmMain frmHelp = null;
        public RM6D010_Gamma(frmMain RM6D010)
        {
            frmHelp = RM6D010;
            InitializeComponent();
            frmHelp.Child_window_hide_already = true;
            frmHelp.Child_Gamma_Window_Open_Enable = false;//防止重复开启子窗体    
        }  //publi
        //RM6D010 监听卸载
        private void RM6D010_Gamma_FormClosed(object sender, FormClosedEventArgs e)
        {
            frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(RM6D010_DataReceived);
            frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);
            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "RM6D010_Gamma_FormClosed！\r\n";
            frmHelp.Child_Gamma_Window_Open_Enable = true; //允许其他子窗体打开
            frmHelp.Child_window_hide_already = false;
            frmHelp.IC_comboBox.Enabled = true;
        }

        private void RM6D010_Gamma_VisibleChanged(object sender, EventArgs e)
        {
            if (frmHelp.Child_window_hide_already == false) //子窗体已开启标识
            {
                frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(RM6D010_DataReceived);
                frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);
                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "RM6D010_Gamma_FormHide！\r\n";
                frmHelp.Child_window_hide_already = true; //子窗体已隐藏标识
            }
            else
            {
                frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);
                frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(RM6D010_DataReceived);
                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "RM6D010_Gamma_FormOpened！\r\n";
                frmHelp.Child_window_hide_already = false; //子窗体已开启标识
            }
        }

        //串口接收
        private void RM6D010_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)//Getting data from Comm Port
        {
            if (IClosing) return;
            try
            {
                Listening = true;//设置标记，说明我已经开始处理数据，一会儿要使用系统UI的。         
                int n = frmHelp.comPort.BytesToRead;
                byte[] buf = new byte[n];
                byte data;

                frmHelp.comPort.Read(buf, 0, n);//读取缓冲数据     
                bool data_1_catched = false;//缓存记录数据是否捕获到    
                buffer.AddRange(buf);
                byte CRCH, CRCL;
                if (buffer.Count > 3)
                {
                    // 0x3D: R66455 的Gamma读写、寄存器读写、OTP读写    设置  返回
                    if (buffer[0] == 0x3D && Setting.TempRecord.cmdLen > 0)
                    {
                        if (buffer.Count >= Setting.TempRecord.cmdLen)
                        {
                            Rec_tmp = new byte[Setting.TempRecord.cmdLen];
                            byte[] crcTemp = new byte[Setting.TempRecord.cmdLen];
                            buffer.CopyTo(0, crcTemp, 0, Setting.TempRecord.cmdLen);

                            CRCData.CalculateCrc16(crcTemp, out CRCH, out CRCL);
                            if (buffer[Setting.TempRecord.cmdLen - 2] != CRCH && buffer[Setting.TempRecord.cmdLen - 1] != CRCL)     //CRC校验出错
                            {
                                buffer.RemoveRange(0, buffer.Count);
                            }
                            else
                            {
                                buffer.CopyTo(0, Rec_tmp, 0, Setting.TempRecord.cmdLen);//复制一条完整数据到具体的数据缓存   
                                data_1_catched = true;
                                buffer.RemoveRange(0, Setting.TempRecord.cmdLen);//正确分析一条数据，从缓存中移除数据。 
                            }

                        }
                    }
                    else
                    {
                        buffer.RemoveRange(0, buffer.Count);
                    }
                }
                if (data_1_catched)
                {
                    this.Invoke((EventHandler)(delegate
                    {
                        frmHelp.T1.Enabled = false; //停止超时计数
                        if (Rec_tmp[0] == 0x3D)  //RM6D010
                        {
                            switch (Rec_tmp[1])
                            {
                                case 0x01:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "寄存器\t写 OK！\r\n";
                                    }
                                    break;

                                case 0x02:
                                    {
                                        if (Setting.TempRecord.RM6D010CmdType == 0x01)  //register read
                                        {
                                            string tmp = "";
                                            tmp = String.Format("{0:X2}", Rec_tmp[4]);//16进制
                                            R6D010_Reg_Data.Text = tmp;
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "寄存器\t读 OK！\r\n";
                                        }
                                    }
                                    break;

                                case 0x0A:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写Gamma1 OTP\t写 OK！\r\n";
                                        else if (Rec_tmp[3] == 0x02)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写Gamma1 OTP\t写 ERROR！\r\n";
                                    }
                                    break;
                                case 0x0D:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写Gamma2 OTP\t写 OK！\r\n";
                                        else if (Rec_tmp[3] == 0x02)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写Gamma2 OTP\t写 ERROR！\r\n";
                                    }
                                    break;
                                case 0x0E:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写Gamma3 OTP\t写 OK！\r\n";
                                        else if (Rec_tmp[3] == 0x02)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写Gamma3 OTP\t写 ERROR！\r\n";
                                    }
                                    break;
                                case 0x0B:
                                    {
                                        if (Setting.TempRecord.RM6D010CmdType == 0x06)  //读OTP烧录次数
                                        {
                                            string tmp = "";
                                            tmp = String.Format("{0:X2}", Rec_tmp[4]);
                                            //RMOTPtime.Text = tmp;

                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Gamma1 OTP\t读 OK！\r\n";
                                        }
                                    }
                                    break;
                                case 0x1B:
                                    {
                                        if (Setting.TempRecord.RM6D010CmdType == 0x06)  //读OTP烧录次数
                                        {
                                            string tmp = "";
                                            tmp = String.Format("{0:X2}", Rec_tmp[4]);
                                            //RMOTPtime.Text = tmp;

                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Gamma2 OTP\t读 OK！\r\n";
                                        }
                                    }
                                    break;
                                case 0x08:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                        {
                                            if ((Rec_tmp[3] & 0xf0) == 0x00)
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "红 Gamma数据\t写 OK！\r\n";
                                            else if ((Rec_tmp[3] & 0xf0) == 0x40)
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "绿 Gamma数据\t写 OK！\r\n";
                                            else if ((Rec_tmp[3] & 0xf0) == 0x80)
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "蓝 Gamma数据\t写 OK！\r\n";
                                        }
                                    }
                                    break;

                                case 0x0C:
                                    {
                                        if (Setting.TempRecord.RM6D010CmdType == 0x03)  // Rred
                                        {
                                            rm010_R0.Value = Decimal.Parse((Rec_tmp[4] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            rm010_R7.Value = Decimal.Parse((Rec_tmp[6] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            rm010_R11.Value = Decimal.Parse((Rec_tmp[8] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            rm010_R15.Value = Decimal.Parse((Rec_tmp[10] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            rm010_R23.Value = Decimal.Parse((Rec_tmp[12] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            rm010_R31.Value = Decimal.Parse((Rec_tmp[14] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            rm010_R39.Value = Decimal.Parse((Rec_tmp[16] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            rm010_R47.Value = Decimal.Parse((Rec_tmp[18] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());
                                            rm010_R63.Value = Decimal.Parse((Rec_tmp[20] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            rm010_R79.Value = Decimal.Parse((Rec_tmp[22] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            rm010_R95.Value = Decimal.Parse((Rec_tmp[24] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            rm010_R111.Value = Decimal.Parse((Rec_tmp[26] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            rm010_R127.Value = Decimal.Parse((Rec_tmp[28] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            rm010_R143.Value = Decimal.Parse((Rec_tmp[30] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            rm010_R159.Value = Decimal.Parse((Rec_tmp[32] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            rm010_R175.Value = Decimal.Parse((Rec_tmp[34] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());
                                            rm010_R191.Value = Decimal.Parse((Rec_tmp[36] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            rm010_R207.Value = Decimal.Parse((Rec_tmp[38] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            rm010_R215.Value = Decimal.Parse((Rec_tmp[40] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            rm010_R223.Value = Decimal.Parse((Rec_tmp[42] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            rm010_R231.Value = Decimal.Parse((Rec_tmp[44] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            rm010_R239.Value = Decimal.Parse((Rec_tmp[46] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            rm010_R243.Value = Decimal.Parse((Rec_tmp[48] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            rm010_R247.Value = Decimal.Parse((Rec_tmp[50] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());
                                            rm010_R255.Value = Decimal.Parse((Rec_tmp[52] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "红 Gamma数据\t读 OK！\r\n";
                                        }
                                        else if (Setting.TempRecord.RM6D010CmdType == 0x04)  // Rgreen
                                        {
                                            rm010_G0.Value = Decimal.Parse((Rec_tmp[4] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            rm010_G7.Value = Decimal.Parse((Rec_tmp[6] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            rm010_G11.Value = Decimal.Parse((Rec_tmp[8] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            rm010_G15.Value = Decimal.Parse((Rec_tmp[10] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            rm010_G23.Value = Decimal.Parse((Rec_tmp[12] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            rm010_G31.Value = Decimal.Parse((Rec_tmp[14] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            rm010_G39.Value = Decimal.Parse((Rec_tmp[16] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            rm010_G47.Value = Decimal.Parse((Rec_tmp[18] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());
                                            rm010_G63.Value = Decimal.Parse((Rec_tmp[20] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            rm010_G79.Value = Decimal.Parse((Rec_tmp[22] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            rm010_G95.Value = Decimal.Parse((Rec_tmp[24] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            rm010_G111.Value = Decimal.Parse((Rec_tmp[26] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            rm010_G127.Value = Decimal.Parse((Rec_tmp[28] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            rm010_G143.Value = Decimal.Parse((Rec_tmp[30] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            rm010_G159.Value = Decimal.Parse((Rec_tmp[32] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            rm010_G175.Value = Decimal.Parse((Rec_tmp[34] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());
                                            rm010_G191.Value = Decimal.Parse((Rec_tmp[36] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            rm010_G207.Value = Decimal.Parse((Rec_tmp[38] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            rm010_G215.Value = Decimal.Parse((Rec_tmp[40] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            rm010_G223.Value = Decimal.Parse((Rec_tmp[42] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            rm010_G231.Value = Decimal.Parse((Rec_tmp[44] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            rm010_G239.Value = Decimal.Parse((Rec_tmp[46] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            rm010_G243.Value = Decimal.Parse((Rec_tmp[48] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            rm010_G247.Value = Decimal.Parse((Rec_tmp[50] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());
                                            rm010_G255.Value = Decimal.Parse((Rec_tmp[52] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "绿 Gamma数据\t读 OK！\r\n";
                                        }
                                        else if (Setting.TempRecord.RM6D010CmdType == 0x05)  // Rblue
                                        {
                                            rm010_B0.Value = Decimal.Parse((Rec_tmp[4] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            rm010_B7.Value = Decimal.Parse((Rec_tmp[6] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            rm010_B11.Value = Decimal.Parse((Rec_tmp[8] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            rm010_B15.Value = Decimal.Parse((Rec_tmp[10] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            rm010_B23.Value = Decimal.Parse((Rec_tmp[12] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            rm010_B31.Value = Decimal.Parse((Rec_tmp[14] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            rm010_B39.Value = Decimal.Parse((Rec_tmp[16] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            rm010_B47.Value = Decimal.Parse((Rec_tmp[18] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());
                                            rm010_B63.Value = Decimal.Parse((Rec_tmp[20] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            rm010_B79.Value = Decimal.Parse((Rec_tmp[22] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            rm010_B95.Value = Decimal.Parse((Rec_tmp[24] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            rm010_B111.Value = Decimal.Parse((Rec_tmp[26] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            rm010_B127.Value = Decimal.Parse((Rec_tmp[28] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            rm010_B143.Value = Decimal.Parse((Rec_tmp[30] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            rm010_B159.Value = Decimal.Parse((Rec_tmp[32] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            rm010_B175.Value = Decimal.Parse((Rec_tmp[34] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());
                                            rm010_B191.Value = Decimal.Parse((Rec_tmp[36] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            rm010_B207.Value = Decimal.Parse((Rec_tmp[38] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            rm010_B215.Value = Decimal.Parse((Rec_tmp[40] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            rm010_B223.Value = Decimal.Parse((Rec_tmp[42] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            rm010_B231.Value = Decimal.Parse((Rec_tmp[44] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            rm010_B239.Value = Decimal.Parse((Rec_tmp[46] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            rm010_B243.Value = Decimal.Parse((Rec_tmp[48] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            rm010_B247.Value = Decimal.Parse((Rec_tmp[50] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());
                                            rm010_B255.Value = Decimal.Parse((Rec_tmp[52] & 0x07).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "蓝 Gamma数据\t读 OK！\r\n";
                                        }
                                    }
                                    break;
                                case 0x11:
                                    {
                                        switch (Rec_tmp[3])
                                        {
                                            case 0x01:
                                            case 0x02:
                                            case 0x03:
                                                {
                                                    frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Gamma切换成功！\r\n";

                                                }
                                                break;
                                            default:
                                                break;
                                        }
                                    }
                                    break;
                            }
                        }
                        frmHelp.textBox1.SelectionStart = this.frmHelp.textBox1.Text.Length;
                        frmHelp.textBox1.ScrollToCaret();//滚动到光标处
                        if (frmHelp.textBox1.Lines.Length > 50) frmHelp.textBox1.Text = null;
                    }));
                }
            }
            finally
            {
                Listening = false;
            }
        }
        //Gamma保存
        private void RM6D010_SaveGamma_Click(object sender, EventArgs e)
        {
            SaveFileDialog sf = new SaveFileDialog(); //对话框
            sf.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; //定义保存的文件的类型
            string str = "保存Gamma文件";
            if (sf.ShowDialog() == DialogResult.OK) //如果确定保存
            {
                if (sf.FileName == "") return; //如果没有输入文件名
                try
                {
                    StreamWriter sw = null; //文件流
                    sw = new StreamWriter(sf.FileName, false, Encoding.UTF8);
                    str = str + "R0," + rm010_R0.Text + "," + "G0," + rm010_G0.Text + "," + "B0," + rm010_B0.Text + "\r\n";
                    str = str + "R7," + rm010_R7.Text + "," + "G7," + rm010_G7.Text + "," + "B7," + rm010_B7.Text + "\r\n";
                    str = str + "R11," + rm010_R11.Text + "," + "G11," + rm010_G11.Text + "," + "B11," + rm010_B11.Text + "\r\n";
                    str = str + "R15," + rm010_R15.Text + "," + "G15," + rm010_G15.Text + "," + "B15," + rm010_B15.Text + "\r\n";
                    str = str + "R23," + rm010_R23.Text + "," + "G23," + rm010_G23.Text + "," + "B23," + rm010_B23.Text + "\r\n";
                    str = str + "R31," + rm010_R31.Text + "," + "G31," + rm010_G31.Text + "," + "B31," + rm010_B31.Text + "\r\n";
                    str = str + "R39," + rm010_R39.Text + "," + "G39," + rm010_G39.Text + "," + "B39," + rm010_B39.Text + "\r\n";
                    str = str + "R47," + rm010_R47.Text + "," + "G47," + rm010_G47.Text + "," + "B47," + rm010_B47.Text + "\r\n";
                    str = str + "R63," + rm010_R63.Text + "," + "G63," + rm010_G63.Text + "," + "B63," + rm010_B63.Text + "\r\n";
                    str = str + "R79," + rm010_R79.Text + "," + "G79," + rm010_G79.Text + "," + "B79," + rm010_B79.Text + "\r\n";
                    str = str + "R95," + rm010_R95.Text + "," + "G95," + rm010_G95.Text + "," + "B95," + rm010_B95.Text + "\r\n";
                    str = str + "R111," + rm010_R111.Text + "," + "G111," + rm010_G111.Text + "," + "B111," + rm010_B111.Text + "\r\n";
                    str = str + "R127," + rm010_R127.Text + "," + "G127," + rm010_G127.Text + "," + "B127," + rm010_B127.Text + "\r\n";
                    str = str + "R143," + rm010_R143.Text + "," + "G143," + rm010_G143.Text + "," + "B143," + rm010_B143.Text + "\r\n";
                    str = str + "R159," + rm010_R159.Text + "," + "G159," + rm010_G159.Text + "," + "B159," + rm010_B159.Text + "\r\n";
                    str = str + "R175," + rm010_R175.Text + "," + "G175," + rm010_G175.Text + "," + "B175," + rm010_B175.Text + "\r\n";
                    str = str + "R191," + rm010_R191.Text + "," + "G191," + rm010_G191.Text + "," + "B191," + rm010_B191.Text + "\r\n";
                    str = str + "R207," + rm010_R207.Text + "," + "G207," + rm010_G207.Text + "," + "B207," + rm010_B207.Text + "\r\n";
                    str = str + "R215," + rm010_R215.Text + "," + "G215," + rm010_G215.Text + "," + "B215," + rm010_B215.Text + "\r\n";
                    str = str + "R223," + rm010_R223.Text + "," + "G223," + rm010_G223.Text + "," + "B223," + rm010_B223.Text + "\r\n";
                    str = str + "R231," + rm010_R231.Text + "," + "G231," + rm010_G231.Text + "," + "B231," + rm010_B231.Text + "\r\n";
                    str = str + "R239," + rm010_R239.Text + "," + "G239," + rm010_G239.Text + "," + "B239," + rm010_B239.Text + "\r\n";
                    str = str + "R243," + rm010_R243.Text + "," + "G243," + rm010_G243.Text + "," + "B243," + rm010_B243.Text + "\r\n";
                    str = str + "R247," + rm010_R247.Text + "," + "G247," + rm010_G247.Text + "," + "B247," + rm010_B247.Text + "\r\n";
                    str = str + "R255," + rm010_R255.Text + "," + "G255," + rm010_G255.Text + "," + "B255," + rm010_B255.Text + "\r\n";
                    sw.WriteLine(str);
                    sw.Dispose(); //释放资源
                    sw.Close(); //关闭数据流
                    MessageBox.Show("Gamma保存OK！", "系统提示：");
                }
                catch
                {
                    MessageBox.Show("Gamma保存时发生错误，请再试！", "系统提示：");
                }
            }
        } //
        //Gamma载入
        private void RM6D010_LoadGamma_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();
            string strtmp = "";
            of.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; ;
            of.Title = "打开Gamma文件";

            if (of.ShowDialog() == DialogResult.OK)
            {
                //读取文本信息
                FileStream fs = new FileStream(of.FileName, FileMode.Open, FileAccess.Read);
                StreamReader streamReader = new StreamReader(fs, Encoding.GetEncoding("GBK"));
                streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                string strLine = streamReader.ReadLine();
                //循环读取文本信息
                while (!string.IsNullOrEmpty(strLine))
                {
                    strtmp = strtmp + strLine + ",";
                    strLine = streamReader.ReadLine(); //循环读取下一行
                }
                fs.Close(); //关闭流
                streamReader.Close();
                string[] arrtmp = strtmp.Split(new Char[] { ',' });
                rm010_R0.Text = arrtmp[1].ToString(); rm010_G0.Text = arrtmp[3].ToString(); rm010_B0.Text = arrtmp[5].ToString();
                rm010_R7.Text = arrtmp[7].ToString(); rm010_G7.Text = arrtmp[9].ToString(); rm010_B7.Text = arrtmp[11].ToString();
                rm010_R11.Text = arrtmp[13].ToString(); rm010_G11.Text = arrtmp[15].ToString(); rm010_B11.Text = arrtmp[17].ToString();
                rm010_R15.Text = arrtmp[19].ToString(); rm010_G15.Text = arrtmp[21].ToString(); rm010_B15.Text = arrtmp[23].ToString();
                rm010_R23.Text = arrtmp[25].ToString(); rm010_G23.Text = arrtmp[27].ToString(); rm010_B23.Text = arrtmp[29].ToString();
                rm010_R31.Text = arrtmp[31].ToString(); rm010_G31.Text = arrtmp[33].ToString(); rm010_B31.Text = arrtmp[35].ToString();
                rm010_R39.Text = arrtmp[37].ToString(); rm010_G39.Text = arrtmp[39].ToString(); rm010_B39.Text = arrtmp[41].ToString();
                rm010_R47.Text = arrtmp[43].ToString(); rm010_G47.Text = arrtmp[45].ToString(); rm010_B47.Text = arrtmp[47].ToString();
                rm010_R63.Text = arrtmp[49].ToString(); rm010_G63.Text = arrtmp[51].ToString(); rm010_B63.Text = arrtmp[53].ToString();
                rm010_R79.Text = arrtmp[55].ToString(); rm010_G79.Text = arrtmp[57].ToString(); rm010_B79.Text = arrtmp[59].ToString();
                rm010_R95.Text = arrtmp[61].ToString(); rm010_G95.Text = arrtmp[63].ToString(); rm010_B95.Text = arrtmp[65].ToString();
                rm010_R111.Text = arrtmp[67].ToString(); rm010_G111.Text = arrtmp[69].ToString(); rm010_B111.Text = arrtmp[71].ToString();
                rm010_R127.Text = arrtmp[73].ToString(); rm010_G127.Text = arrtmp[75].ToString(); rm010_B127.Text = arrtmp[77].ToString();
                rm010_R143.Text = arrtmp[79].ToString(); rm010_G143.Text = arrtmp[81].ToString(); rm010_B143.Text = arrtmp[83].ToString();
                rm010_R159.Text = arrtmp[85].ToString(); rm010_G159.Text = arrtmp[87].ToString(); rm010_B159.Text = arrtmp[89].ToString();
                rm010_R175.Text = arrtmp[91].ToString(); rm010_G175.Text = arrtmp[93].ToString(); rm010_B175.Text = arrtmp[95].ToString();
                rm010_R191.Text = arrtmp[97].ToString(); rm010_G191.Text = arrtmp[99].ToString(); rm010_B191.Text = arrtmp[101].ToString();
                rm010_R207.Text = arrtmp[103].ToString(); rm010_G207.Text = arrtmp[105].ToString(); rm010_B207.Text = arrtmp[107].ToString();
                rm010_R215.Text = arrtmp[109].ToString(); rm010_G215.Text = arrtmp[111].ToString(); rm010_B215.Text = arrtmp[113].ToString();
                rm010_R223.Text = arrtmp[115].ToString(); rm010_G223.Text = arrtmp[117].ToString(); rm010_B223.Text = arrtmp[119].ToString();
                rm010_R231.Text = arrtmp[121].ToString(); rm010_G231.Text = arrtmp[123].ToString(); rm010_B231.Text = arrtmp[125].ToString();
                rm010_R239.Text = arrtmp[127].ToString(); rm010_G239.Text = arrtmp[129].ToString(); rm010_B239.Text = arrtmp[131].ToString();
                rm010_R243.Text = arrtmp[133].ToString(); rm010_G243.Text = arrtmp[135].ToString(); rm010_B243.Text = arrtmp[137].ToString();
                rm010_R247.Text = arrtmp[139].ToString(); rm010_G247.Text = arrtmp[141].ToString(); rm010_B247.Text = arrtmp[143].ToString();
                rm010_R255.Text = arrtmp[145].ToString(); rm010_G255.Text = arrtmp[147].ToString(); rm010_B255.Text = arrtmp[149].ToString();
            }
        }




        private void RM010_Gamma_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;
            Send_buf = new byte[56];
            Setting.TempRecord.cmdLen = 56;
            Send_buf[2] = 51;
            Send_buf[3] = 0;
            Send_buf[0] = 0x3D; //RM6D010

            switch (btnTmp.Name)
            {
                case "RM6D010_GammaR_Red":             //Read R
                    {
                        Setting.TempRecord.RM6D010CmdType = 0x03;       //      3
                        Send_buf[1] = 0x09;                             //读Gamma
                        Send_buf[3] |= 0x00;                            //红色red
                        if (radioButton010_Gamma1.Checked == true)
                        {
                            Send_buf[4] = 0x00;
                        }
                        else if (radioButton010_Gamma2.Checked == true)
                        {
                            Send_buf[4] = 0x01;
                        }
                        else if (radioButton010_Gamma3.Checked == true)
                        {
                            Send_buf[4] = 0x02;
                        }
                    }
                    break;
                case "RM6D010_GammaR_Green":
                    {
                        Setting.TempRecord.RM6D010CmdType = 0x04;   //      4
                        Send_buf[1] = 0x09;                         //  读Gamma
                        Send_buf[3] |= 0x42;                        //绿色 green
                        if (radioButton010_Gamma1.Checked == true)
                        {
                            Send_buf[4] = 0x00;
                        }
                        else if (radioButton010_Gamma2.Checked == true)
                        {
                            Send_buf[4] = 0x01;
                        }
                        else if (radioButton010_Gamma3.Checked == true)
                        {
                            Send_buf[4] = 0x02;
                        }
                    }
                    break;
                case "RM6D010_GammaR_Blue":
                    {
                        Setting.TempRecord.RM6D010CmdType = 0x05;   //      5
                        Send_buf[1] = 0x09;                         //   读Gamma
                        Send_buf[3] |= 0x81;                        //   blue
                        if (radioButton010_Gamma1.Checked == true)
                        {
                            Send_buf[4] = 0x00;
                        }
                        else if (radioButton010_Gamma2.Checked == true)
                        {
                            Send_buf[4] = 0x01;
                        }
                        else if (radioButton010_Gamma3.Checked == true)
                        {
                            Send_buf[4] = 0x02;
                        }
                    }
                    break;
                //--------------------------------------
                case "RM6D010_GammaW_Red":
                    {
                        Send_buf[1] = 0x08;                       //写Gamma
                        if (radioButton010_Gamma1.Checked == true)
                        {
                            Send_buf[3] = 0x00;
                        }
                        else if (radioButton010_Gamma2.Checked == true)
                        {
                            Send_buf[3] = 0x01;
                        }
                        else if (radioButton010_Gamma3.Checked == true)
                        {
                            Send_buf[3] = 0x02;
                        }
                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(rm010_R0.Value.ToString()) >> 8);
                        Send_buf[5] = Convert.ToByte((Convert.ToUInt16(rm010_R0.Value.ToString())) & 0xff);
                        Send_buf[6] = Convert.ToByte(Convert.ToUInt16(rm010_R7.Value.ToString()) >> 8);
                        Send_buf[7] = Convert.ToByte((Convert.ToUInt16(rm010_R7.Value.ToString())) & 0xff);
                        Send_buf[8] = Convert.ToByte(Convert.ToUInt16(rm010_R11.Value.ToString()) >> 8);
                        Send_buf[9] = Convert.ToByte((Convert.ToUInt16(rm010_R11.Value.ToString())) & 0xff);
                        Send_buf[10] = Convert.ToByte(Convert.ToUInt16(rm010_R15.Value.ToString()) >> 8);
                        Send_buf[11] = Convert.ToByte((Convert.ToUInt16(rm010_R15.Value.ToString())) & 0xff);
                        Send_buf[12] = Convert.ToByte(Convert.ToUInt16(rm010_R23.Value.ToString()) >> 8);
                        Send_buf[13] = Convert.ToByte((Convert.ToUInt16(rm010_R23.Value.ToString())) & 0xff);
                        Send_buf[14] = Convert.ToByte(Convert.ToUInt16(rm010_R31.Value.ToString()) >> 8);
                        Send_buf[15] = Convert.ToByte((Convert.ToUInt16(rm010_R31.Value.ToString())) & 0xff);
                        Send_buf[16] = Convert.ToByte(Convert.ToUInt16(rm010_R39.Value.ToString()) >> 8);
                        Send_buf[17] = Convert.ToByte((Convert.ToUInt16(rm010_R39.Value.ToString())) & 0xff);
                        Send_buf[18] = Convert.ToByte(Convert.ToUInt16(rm010_R47.Value.ToString()) >> 8);
                        Send_buf[19] = Convert.ToByte((Convert.ToUInt16(rm010_R47.Value.ToString())) & 0xff);
                        Send_buf[20] = Convert.ToByte(Convert.ToUInt16(rm010_R63.Value.ToString()) >> 8);
                        Send_buf[21] = Convert.ToByte((Convert.ToUInt16(rm010_R63.Value.ToString())) & 0xff);
                        Send_buf[22] = Convert.ToByte(Convert.ToUInt16(rm010_R79.Value.ToString()) >> 8);
                        Send_buf[23] = Convert.ToByte((Convert.ToUInt16(rm010_R79.Value.ToString())) & 0xff);
                        Send_buf[24] = Convert.ToByte(Convert.ToUInt16(rm010_R95.Value.ToString()) >> 8);
                        Send_buf[25] = Convert.ToByte((Convert.ToUInt16(rm010_R95.Value.ToString())) & 0xff);
                        Send_buf[26] = Convert.ToByte(Convert.ToUInt16(rm010_R111.Value.ToString()) >> 8);
                        Send_buf[27] = Convert.ToByte((Convert.ToUInt16(rm010_R111.Value.ToString())) & 0xff);
                        Send_buf[28] = Convert.ToByte(Convert.ToUInt16(rm010_R127.Value.ToString()) >> 8);
                        Send_buf[29] = Convert.ToByte((Convert.ToUInt16(rm010_R127.Value.ToString())) & 0xff);
                        Send_buf[30] = Convert.ToByte(Convert.ToUInt16(rm010_R143.Value.ToString()) >> 8);
                        Send_buf[31] = Convert.ToByte((Convert.ToUInt16(rm010_R143.Value.ToString())) & 0xff);
                        Send_buf[32] = Convert.ToByte(Convert.ToUInt16(rm010_R159.Value.ToString()) >> 8);
                        Send_buf[33] = Convert.ToByte((Convert.ToUInt16(rm010_R159.Value.ToString())) & 0xff);
                        Send_buf[34] = Convert.ToByte(Convert.ToUInt16(rm010_R175.Value.ToString()) >> 8);
                        Send_buf[35] = Convert.ToByte((Convert.ToUInt16(rm010_R175.Value.ToString())) & 0xff);
                        Send_buf[36] = Convert.ToByte(Convert.ToUInt16(rm010_R191.Value.ToString()) >> 8);
                        Send_buf[37] = Convert.ToByte((Convert.ToUInt16(rm010_R191.Value.ToString())) & 0xff);
                        Send_buf[38] = Convert.ToByte(Convert.ToUInt16(rm010_R207.Value.ToString()) >> 8);
                        Send_buf[39] = Convert.ToByte((Convert.ToUInt16(rm010_R207.Value.ToString())) & 0xff);
                        Send_buf[40] = Convert.ToByte(Convert.ToUInt16(rm010_R215.Value.ToString()) >> 8);
                        Send_buf[41] = Convert.ToByte((Convert.ToUInt16(rm010_R215.Value.ToString())) & 0xff);
                        Send_buf[42] = Convert.ToByte(Convert.ToUInt16(rm010_R223.Value.ToString()) >> 8);
                        Send_buf[43] = Convert.ToByte((Convert.ToUInt16(rm010_R223.Value.ToString())) & 0xff);
                        Send_buf[44] = Convert.ToByte(Convert.ToUInt16(rm010_R231.Value.ToString()) >> 8);
                        Send_buf[45] = Convert.ToByte((Convert.ToUInt16(rm010_R231.Value.ToString())) & 0xff);
                        Send_buf[46] = Convert.ToByte(Convert.ToUInt16(rm010_R239.Value.ToString()) >> 8);
                        Send_buf[47] = Convert.ToByte((Convert.ToUInt16(rm010_R239.Value.ToString())) & 0xff);
                        Send_buf[48] = Convert.ToByte(Convert.ToUInt16(rm010_R243.Value.ToString()) >> 8);
                        Send_buf[49] = Convert.ToByte((Convert.ToUInt16(rm010_R243.Value.ToString())) & 0xff);
                        Send_buf[50] = Convert.ToByte(Convert.ToUInt16(rm010_R247.Value.ToString()) >> 8);
                        Send_buf[51] = Convert.ToByte((Convert.ToUInt16(rm010_R247.Value.ToString())) & 0xff);
                        Send_buf[52] = Convert.ToByte(Convert.ToUInt16(rm010_R255.Value.ToString()) >> 8);
                        Send_buf[53] = Convert.ToByte((Convert.ToUInt16(rm010_R255.Value.ToString())) & 0xff);
                    }
                    break;
                case "RM6D010_GammaW_Green":
                    {
                        Send_buf[1] = 0x08;
                        if (radioButton010_Gamma1.Checked == true)
                        {
                            Send_buf[3] = 0x40;
                        }
                        else if (radioButton010_Gamma2.Checked == true)
                        {
                            Send_buf[3] = 0x41;
                        }
                        else if (radioButton010_Gamma3.Checked == true)
                        {
                            Send_buf[3] = 0x42;
                        }
                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(rm010_G0.Value.ToString()) >> 8);
                        Send_buf[5] = Convert.ToByte((Convert.ToUInt16(rm010_G0.Value.ToString())) & 0xff);
                        Send_buf[6] = Convert.ToByte(Convert.ToUInt16(rm010_G7.Value.ToString()) >> 8);
                        Send_buf[7] = Convert.ToByte((Convert.ToUInt16(rm010_G7.Value.ToString())) & 0xff);
                        Send_buf[8] = Convert.ToByte(Convert.ToUInt16(rm010_G11.Value.ToString()) >> 8);
                        Send_buf[9] = Convert.ToByte((Convert.ToUInt16(rm010_G11.Value.ToString())) & 0xff);
                        Send_buf[10] = Convert.ToByte(Convert.ToUInt16(rm010_G15.Value.ToString()) >> 8);
                        Send_buf[11] = Convert.ToByte((Convert.ToUInt16(rm010_G15.Value.ToString())) & 0xff);
                        Send_buf[12] = Convert.ToByte(Convert.ToUInt16(rm010_G23.Value.ToString()) >> 8);
                        Send_buf[13] = Convert.ToByte((Convert.ToUInt16(rm010_G23.Value.ToString())) & 0xff);
                        Send_buf[14] = Convert.ToByte(Convert.ToUInt16(rm010_G31.Value.ToString()) >> 8);
                        Send_buf[15] = Convert.ToByte((Convert.ToUInt16(rm010_G31.Value.ToString())) & 0xff);
                        Send_buf[16] = Convert.ToByte(Convert.ToUInt16(rm010_G39.Value.ToString()) >> 8);
                        Send_buf[17] = Convert.ToByte((Convert.ToUInt16(rm010_G39.Value.ToString())) & 0xff);
                        Send_buf[18] = Convert.ToByte(Convert.ToUInt16(rm010_G47.Value.ToString()) >> 8);
                        Send_buf[19] = Convert.ToByte((Convert.ToUInt16(rm010_G47.Value.ToString())) & 0xff);
                        Send_buf[20] = Convert.ToByte(Convert.ToUInt16(rm010_G63.Value.ToString()) >> 8);
                        Send_buf[21] = Convert.ToByte((Convert.ToUInt16(rm010_G63.Value.ToString())) & 0xff);
                        Send_buf[22] = Convert.ToByte(Convert.ToUInt16(rm010_G79.Value.ToString()) >> 8);
                        Send_buf[23] = Convert.ToByte((Convert.ToUInt16(rm010_G79.Value.ToString())) & 0xff);
                        Send_buf[24] = Convert.ToByte(Convert.ToUInt16(rm010_G95.Value.ToString()) >> 8);
                        Send_buf[25] = Convert.ToByte((Convert.ToUInt16(rm010_G95.Value.ToString())) & 0xff);
                        Send_buf[26] = Convert.ToByte(Convert.ToUInt16(rm010_G111.Value.ToString()) >> 8);
                        Send_buf[27] = Convert.ToByte((Convert.ToUInt16(rm010_G111.Value.ToString())) & 0xff);
                        Send_buf[28] = Convert.ToByte(Convert.ToUInt16(rm010_G127.Value.ToString()) >> 8);
                        Send_buf[29] = Convert.ToByte((Convert.ToUInt16(rm010_G127.Value.ToString())) & 0xff);
                        Send_buf[30] = Convert.ToByte(Convert.ToUInt16(rm010_G143.Value.ToString()) >> 8);
                        Send_buf[31] = Convert.ToByte((Convert.ToUInt16(rm010_G143.Value.ToString())) & 0xff);
                        Send_buf[32] = Convert.ToByte(Convert.ToUInt16(rm010_G159.Value.ToString()) >> 8);
                        Send_buf[33] = Convert.ToByte((Convert.ToUInt16(rm010_G159.Value.ToString())) & 0xff);
                        Send_buf[34] = Convert.ToByte(Convert.ToUInt16(rm010_G175.Value.ToString()) >> 8);
                        Send_buf[35] = Convert.ToByte((Convert.ToUInt16(rm010_G175.Value.ToString())) & 0xff);
                        Send_buf[36] = Convert.ToByte(Convert.ToUInt16(rm010_G191.Value.ToString()) >> 8);
                        Send_buf[37] = Convert.ToByte((Convert.ToUInt16(rm010_G191.Value.ToString())) & 0xff);
                        Send_buf[38] = Convert.ToByte(Convert.ToUInt16(rm010_G207.Value.ToString()) >> 8);
                        Send_buf[39] = Convert.ToByte((Convert.ToUInt16(rm010_G207.Value.ToString())) & 0xff);
                        Send_buf[40] = Convert.ToByte(Convert.ToUInt16(rm010_G215.Value.ToString()) >> 8);
                        Send_buf[41] = Convert.ToByte((Convert.ToUInt16(rm010_G215.Value.ToString())) & 0xff);
                        Send_buf[42] = Convert.ToByte(Convert.ToUInt16(rm010_G223.Value.ToString()) >> 8);
                        Send_buf[43] = Convert.ToByte((Convert.ToUInt16(rm010_G223.Value.ToString())) & 0xff);
                        Send_buf[44] = Convert.ToByte(Convert.ToUInt16(rm010_G231.Value.ToString()) >> 8);
                        Send_buf[45] = Convert.ToByte((Convert.ToUInt16(rm010_G231.Value.ToString())) & 0xff);
                        Send_buf[46] = Convert.ToByte(Convert.ToUInt16(rm010_G239.Value.ToString()) >> 8);
                        Send_buf[47] = Convert.ToByte((Convert.ToUInt16(rm010_G239.Value.ToString())) & 0xff);
                        Send_buf[48] = Convert.ToByte(Convert.ToUInt16(rm010_G243.Value.ToString()) >> 8);
                        Send_buf[49] = Convert.ToByte((Convert.ToUInt16(rm010_G243.Value.ToString())) & 0xff);
                        Send_buf[50] = Convert.ToByte(Convert.ToUInt16(rm010_G247.Value.ToString()) >> 8);
                        Send_buf[51] = Convert.ToByte((Convert.ToUInt16(rm010_G247.Value.ToString())) & 0xff);
                        Send_buf[52] = Convert.ToByte(Convert.ToUInt16(rm010_G255.Value.ToString()) >> 8);
                        Send_buf[53] = Convert.ToByte((Convert.ToUInt16(rm010_G255.Value.ToString())) & 0xff);

                    }
                    break;
                case "RM6D010_GammaW_Blue":
                    {
                        Send_buf[1] = 0x08;
                        if (radioButton010_Gamma1.Checked == true)
                        {
                            Send_buf[3] = 0x80;
                        }
                        else if (radioButton010_Gamma2.Checked == true)
                        {
                            Send_buf[3] = 0x81;
                        }
                        else if (radioButton010_Gamma3.Checked == true)
                        {
                            Send_buf[3] = 0x82;
                        }

                        Send_buf[4] = Convert.ToByte(Convert.ToUInt16(rm010_B0.Value.ToString()) >> 8);
                        Send_buf[5] = Convert.ToByte((Convert.ToUInt16(rm010_B0.Value.ToString())) & 0xff);
                        Send_buf[6] = Convert.ToByte(Convert.ToUInt16(rm010_B7.Value.ToString()) >> 8);
                        Send_buf[7] = Convert.ToByte((Convert.ToUInt16(rm010_B7.Value.ToString())) & 0xff);
                        Send_buf[8] = Convert.ToByte(Convert.ToUInt16(rm010_B11.Value.ToString()) >> 8);
                        Send_buf[9] = Convert.ToByte((Convert.ToUInt16(rm010_B11.Value.ToString())) & 0xff);
                        Send_buf[10] = Convert.ToByte(Convert.ToUInt16(rm010_B15.Value.ToString()) >> 8);
                        Send_buf[11] = Convert.ToByte((Convert.ToUInt16(rm010_B15.Value.ToString())) & 0xff);
                        Send_buf[12] = Convert.ToByte(Convert.ToUInt16(rm010_B23.Value.ToString()) >> 8);
                        Send_buf[13] = Convert.ToByte((Convert.ToUInt16(rm010_B23.Value.ToString())) & 0xff);
                        Send_buf[14] = Convert.ToByte(Convert.ToUInt16(rm010_B31.Value.ToString()) >> 8);
                        Send_buf[15] = Convert.ToByte((Convert.ToUInt16(rm010_B31.Value.ToString())) & 0xff);
                        Send_buf[16] = Convert.ToByte(Convert.ToUInt16(rm010_B39.Value.ToString()) >> 8);
                        Send_buf[17] = Convert.ToByte((Convert.ToUInt16(rm010_B39.Value.ToString())) & 0xff);
                        Send_buf[18] = Convert.ToByte(Convert.ToUInt16(rm010_B47.Value.ToString()) >> 8);
                        Send_buf[19] = Convert.ToByte((Convert.ToUInt16(rm010_B47.Value.ToString())) & 0xff);
                        Send_buf[20] = Convert.ToByte(Convert.ToUInt16(rm010_B63.Value.ToString()) >> 8);
                        Send_buf[21] = Convert.ToByte((Convert.ToUInt16(rm010_B63.Value.ToString())) & 0xff);
                        Send_buf[22] = Convert.ToByte(Convert.ToUInt16(rm010_B79.Value.ToString()) >> 8);
                        Send_buf[23] = Convert.ToByte((Convert.ToUInt16(rm010_B79.Value.ToString())) & 0xff);
                        Send_buf[24] = Convert.ToByte(Convert.ToUInt16(rm010_B95.Value.ToString()) >> 8);
                        Send_buf[25] = Convert.ToByte((Convert.ToUInt16(rm010_B95.Value.ToString())) & 0xff);
                        Send_buf[26] = Convert.ToByte(Convert.ToUInt16(rm010_B111.Value.ToString()) >> 8);
                        Send_buf[27] = Convert.ToByte((Convert.ToUInt16(rm010_B111.Value.ToString())) & 0xff);
                        Send_buf[28] = Convert.ToByte(Convert.ToUInt16(rm010_B127.Value.ToString()) >> 8);
                        Send_buf[29] = Convert.ToByte((Convert.ToUInt16(rm010_B127.Value.ToString())) & 0xff);
                        Send_buf[30] = Convert.ToByte(Convert.ToUInt16(rm010_B143.Value.ToString()) >> 8);
                        Send_buf[31] = Convert.ToByte((Convert.ToUInt16(rm010_B143.Value.ToString())) & 0xff);
                        Send_buf[32] = Convert.ToByte(Convert.ToUInt16(rm010_B159.Value.ToString()) >> 8);
                        Send_buf[33] = Convert.ToByte((Convert.ToUInt16(rm010_B159.Value.ToString())) & 0xff);
                        Send_buf[34] = Convert.ToByte(Convert.ToUInt16(rm010_B175.Value.ToString()) >> 8);
                        Send_buf[35] = Convert.ToByte((Convert.ToUInt16(rm010_B175.Value.ToString())) & 0xff);
                        Send_buf[36] = Convert.ToByte(Convert.ToUInt16(rm010_B191.Value.ToString()) >> 8);
                        Send_buf[37] = Convert.ToByte((Convert.ToUInt16(rm010_B191.Value.ToString())) & 0xff);
                        Send_buf[38] = Convert.ToByte(Convert.ToUInt16(rm010_B207.Value.ToString()) >> 8);
                        Send_buf[39] = Convert.ToByte((Convert.ToUInt16(rm010_B207.Value.ToString())) & 0xff);
                        Send_buf[40] = Convert.ToByte(Convert.ToUInt16(rm010_B215.Value.ToString()) >> 8);
                        Send_buf[41] = Convert.ToByte((Convert.ToUInt16(rm010_B215.Value.ToString())) & 0xff);
                        Send_buf[42] = Convert.ToByte(Convert.ToUInt16(rm010_B223.Value.ToString()) >> 8);
                        Send_buf[43] = Convert.ToByte((Convert.ToUInt16(rm010_B223.Value.ToString())) & 0xff);
                        Send_buf[44] = Convert.ToByte(Convert.ToUInt16(rm010_B231.Value.ToString()) >> 8);
                        Send_buf[45] = Convert.ToByte((Convert.ToUInt16(rm010_B231.Value.ToString())) & 0xff);
                        Send_buf[46] = Convert.ToByte(Convert.ToUInt16(rm010_B239.Value.ToString()) >> 8);
                        Send_buf[47] = Convert.ToByte((Convert.ToUInt16(rm010_B239.Value.ToString())) & 0xff);
                        Send_buf[48] = Convert.ToByte(Convert.ToUInt16(rm010_B243.Value.ToString()) >> 8);
                        Send_buf[49] = Convert.ToByte((Convert.ToUInt16(rm010_B243.Value.ToString())) & 0xff);
                        Send_buf[50] = Convert.ToByte(Convert.ToUInt16(rm010_B247.Value.ToString()) >> 8);
                        Send_buf[51] = Convert.ToByte((Convert.ToUInt16(rm010_B247.Value.ToString())) & 0xff);
                        Send_buf[52] = Convert.ToByte(Convert.ToUInt16(rm010_B255.Value.ToString()) >> 8);
                        Send_buf[53] = Convert.ToByte((Convert.ToUInt16(rm010_B255.Value.ToString())) & 0xff);

                    }
                    break;
                default:
                    break;
            }

            CRCData.CalculateCrc16(Send_buf, out Send_buf[54], out Send_buf[55]);

            try
            {
                RM010_0XFE_XX = 0x00;
                frmHelp.comPort.Write(Send_buf, 0, 56);   //RM6D010
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            frmHelp.T1.Enabled = false;
            frmHelp.T1.Interval = 2000;
            frmHelp.T1.Enabled = true;

        }
        private void btn010ModeSet_Click(object sender, EventArgs e)
        {
            Send_buf = new byte[7];
            Button btnTmp = (Button)sender;
            Setting.TempRecord.cmdLen = 7;
            Send_buf[0] = 0x3D;
            Send_buf[2] = 0x02;
            switch (btnTmp.Name)
            {
                case "RM6D010_Reg_R":
                    {
                        RM010_0XFE_XX = 0x00;
                        Setting.TempRecord.RM6D010CmdType = 0x01;   //读普通寄存器
                        Send_buf[1] = 0x02;
                        Send_buf[3] = byte.Parse((Convert.ToInt32(R6D010_Reg_Addr.Text.Trim(), 16)).ToString());
                    }
                    break;
                //-------------------------------------------    
                case "RM6D010_Reg_W":         //w写寄存器
                    {
                        RM010_0XFE_XX = 0x00;
                        Send_buf[1] = 0x01;
                        Send_buf[3] = byte.Parse((Convert.ToInt32(R6D010_Reg_Addr.Text.Trim(), 16)).ToString());
                        Send_buf[4] = byte.Parse((Convert.ToInt32(R6D010_Reg_Data.Text.Trim(), 16)).ToString());
                    }
                    break;
                //-------------------------------X----------------      
                case "RM010_OTP_P1":
                    {
                        RM010_0XFE_XX = 0x00;
                        Send_buf[1] = 0x0A;
                    }
                    break;
                case "RM010_OTP_P2":
                    {
                        RM010_0XFE_XX = 0x00;
                        Send_buf[1] = 0x0A;
                    }
                    break;
                case "RM010_OTP_P3":
                    {
                        RM010_0XFE_XX = 0x00;
                        Send_buf[1] = 0x0D;
                    }
                    break;
                case "RM6D010_R_OTPTime":
                    {
                        RM010_0XFE_XX = 0x00;
                        Send_buf[1] = 0x0B;
                        Setting.TempRecord.RM6D010CmdType = 0x02;       //      2
                        if (radioButton20.Checked == true)
                        {
                            Send_buf[3] = 0x00;
                        }
                        else if (radioButton21.Checked == true)
                        {
                            Send_buf[3] = 0x01;
                        }
                        else if (radioButton22.Checked == true)
                        {
                            Send_buf[3] = 0x02;
                        }
                    }
                    break;
                default:
                    break;
            }

            CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
            try
            {
                frmHelp.comPort.Write(Send_buf, 0, 7);
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            frmHelp.T1.Enabled = false;
            frmHelp.T1.Interval = 2000;
            frmHelp.T1.Enabled = true;

        }
        //RM6D010
        private int[] Parttern_RM6D010 = new int[24] { 255, 247, 243, 239, 231, 223, 215, 207, 191, 175, 159, 143, 127, 111, 95, 79, 63, 47, 39, 31, 23, 15, 11, 7 };
        private void btnCalculate010_Click(object sender, EventArgs e)
        {
            txt_010_255.Text = (Math.Pow((Parttern_RM6D010[0] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_247.Text = (Math.Pow((Parttern_RM6D010[1] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_243.Text = (Math.Pow((Parttern_RM6D010[2] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_239.Text = (Math.Pow((Parttern_RM6D010[3] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_231.Text = (Math.Pow((Parttern_RM6D010[4] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_223.Text = (Math.Pow((Parttern_RM6D010[5] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_215.Text = (Math.Pow((Parttern_RM6D010[6] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_207.Text = (Math.Pow((Parttern_RM6D010[7] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_191.Text = (Math.Pow((Parttern_RM6D010[8] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_175.Text = (Math.Pow((Parttern_RM6D010[9] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_159.Text = (Math.Pow((Parttern_RM6D010[10] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_143.Text = (Math.Pow((Parttern_RM6D010[11] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_127.Text = (Math.Pow((Parttern_RM6D010[12] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_111.Text = (Math.Pow((Parttern_RM6D010[13] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_95.Text = (Math.Pow((Parttern_RM6D010[14] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_79.Text = (Math.Pow((Parttern_RM6D010[15] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_63.Text = (Math.Pow((Parttern_RM6D010[16] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_47.Text = (Math.Pow((Parttern_RM6D010[17] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_39.Text = (Math.Pow((Parttern_RM6D010[18] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_31.Text = (Math.Pow((Parttern_RM6D010[19] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_23.Text = (Math.Pow((Parttern_RM6D010[20] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_15.Text = (Math.Pow((Parttern_RM6D010[21] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_11.Text = (Math.Pow((Parttern_RM6D010[22] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
            txt_010_7.Text = (Math.Pow((Parttern_RM6D010[23] / 255.0), Convert.ToDouble(txt_010_gamma.Text)) * Convert.ToDouble(txt_010_l.Text)).ToString("F4");
        }
        private void btn010Stop_Click(object sender, EventArgs e)
        {
            T20.Enabled = false;
            flag1 = 1;
            flag2 = 1;
            flag3 = 1;
            adjust_Rnum = 0;
            adjust_Gnum = 0;
            adjust_Bnum = 0;
            adjust_l = 0;
            adjust_x = 0;
            adjust_y = 0;
        }

        private void T20_Tick(object sender, EventArgs e)
        {
            RM6D010_auto_gamma(null, null);
        }

        private void btnAutoGamma010_Click(object sender, EventArgs e)
        {
            int flag = 2;
            double Lr_d, Lg_d, Lb_d;
            D_lums = new double[24, 3];
            D_lum = new double[24];
            index = 0;
            adjust_Rnum = 0;
            adjust_Gnum = 0;
            adjust_Bnum = 0;
            adjust_l = 0;
            adjust_x = 0;
            adjust_y = 0;

            Button btnTmp = (Button)sender;

            D_lum[0] = Convert.ToDouble(txt_010_255.Text);
            D_lum[1] = Convert.ToDouble(txt_010_247.Text);
            D_lum[2] = Convert.ToDouble(txt_010_243.Text);
            D_lum[3] = Convert.ToDouble(txt_010_239.Text);
            D_lum[4] = Convert.ToDouble(txt_010_231.Text);
            D_lum[5] = Convert.ToDouble(txt_010_223.Text);
            D_lum[6] = Convert.ToDouble(txt_010_215.Text);
            D_lum[7] = Convert.ToDouble(txt_010_207.Text);
            D_lum[8] = Convert.ToDouble(txt_010_191.Text);
            D_lum[9] = Convert.ToDouble(txt_010_175.Text);
            D_lum[10] = Convert.ToDouble(txt_010_159.Text);
            D_lum[11] = Convert.ToDouble(txt_010_143.Text);
            D_lum[12] = Convert.ToDouble(txt_010_127.Text);
            D_lum[13] = Convert.ToDouble(txt_010_111.Text);
            D_lum[14] = Convert.ToDouble(txt_010_95.Text);
            D_lum[15] = Convert.ToDouble(txt_010_79.Text);
            D_lum[16] = Convert.ToDouble(txt_010_63.Text);
            D_lum[17] = Convert.ToDouble(txt_010_47.Text);
            D_lum[18] = Convert.ToDouble(txt_010_39.Text);
            D_lum[19] = Convert.ToDouble(txt_010_31.Text);
            D_lum[20] = Convert.ToDouble(txt_010_23.Text);
            D_lum[21] = Convert.ToDouble(txt_010_15.Text);
            D_lum[22] = Convert.ToDouble(txt_010_11.Text);
            D_lum[23] = Convert.ToDouble(txt_010_7.Text);

            D_x = Convert.ToDouble(txt_010_x.Text);
            D_y = Convert.ToDouble(txt_010_y.Text);
            Lr_d = CaSDKObj.R_y * ((D_y - CaSDKObj.G_y) * (CaSDKObj.B_x - D_x) + (D_x - CaSDKObj.G_x) * (D_y - CaSDKObj.B_y)) / CaSDKObj.B_y / ((D_y - CaSDKObj.G_y) * (D_x - CaSDKObj.R_x) + (D_x - CaSDKObj.G_x) * (CaSDKObj.R_y - D_y));
            Lg_d = CaSDKObj.G_y * ((D_y - CaSDKObj.R_y) * (CaSDKObj.B_x - D_x) + (D_x - CaSDKObj.R_x) * (D_y - CaSDKObj.B_y)) / CaSDKObj.B_y / ((D_y - CaSDKObj.R_y) * (D_x - CaSDKObj.G_x) + (D_x - CaSDKObj.R_x) * (CaSDKObj.G_y - D_y));
            Lb_d = 1.0;
            for (int i = 0; i < 24; i++)
            {
                D_lums[i, 0] = D_lum[i] * Lr_d / (Lr_d + Lg_d + Lb_d);
                D_lums[i, 1] = D_lum[i] * Lg_d / (Lr_d + Lg_d + Lb_d);
                D_lums[i, 2] = D_lum[i] * Lb_d / (Lr_d + Lg_d + Lb_d);
            }
            R6D010_Reg_Addr.Text = "FE";
            if (radioButton010_Gamma1.Checked == true)
                R6D010_Reg_Data.Text = "02";
            else if (radioButton010_Gamma2.Checked == true)
                R6D010_Reg_Data.Text = "03";
            btn010ModeSet_Click(RM6D010_Reg_W, e);

            switch (flag)
            {
                case 1://寄存器值与亮度正比

                    break;
                case 2://寄存器值与亮度反比
                    {
                        lum_off = Convert.ToDouble(txt_010_loff.Text);
                        x_off = Convert.ToDouble(txt_010_xoff.Text);
                        y_off = Convert.ToDouble(txt_010_yoff.Text);
                        Application.DoEvents();
                        frmHelp.OLED_Show_Click(frmHelp.btnwhite, e);
                        T20.Enabled = true;
                    }
                    break;
                default:
                    break;
            }
        }
        private void RM6D010_auto_gamma(Object sender, EventArgs e)
        {
            double Lr_t, Lg_t, Lb_t, lumr, lumg, lumb;
            frmHelp.Msr_CASDK();

            if ((frmHelp.CASDK_LUM < (D_lum[index] + lum_off)) && (frmHelp.CASDK_LUM > (D_lum[index] - lum_off)))//G
                flag1 = 0;
            if ((frmHelp.CASDK_y < (D_y + y_off)) && (frmHelp.CASDK_y > (D_y - y_off)) && flag1 == 0)//B
                flag2 = 0;
            if ((frmHelp.CASDK_x < (D_x + x_off)) && (frmHelp.CASDK_x > (D_x - x_off)) && flag1 == 0 && flag2 == 0)//R
                flag3 = 0;

            if (flag1 == 0 && flag2 == 0 && flag3 == 0)
            {
                T20.Enabled = false;
                index++;
                adjust_Rnum = 0;
                adjust_Gnum = 0;
                adjust_Bnum = 0;
                adjust_l = 0;
                adjust_x = 0;
                adjust_y = 0;
                if (index == 24)
                {
                    frmHelp.textBox1.Text = frmHelp.textBox1.Text + "RM6D010 gamma调试完毕!\r\n";
                }
                if (index <= 23)
                {
                    switch (index)
                    {
                        case 1:
                            lum_off = Convert.ToDouble(txt_010_247off.Text);
                            break;
                        case 2:
                            lum_off = Convert.ToDouble(txt_010_243off.Text);
                            break;
                        case 3:
                            lum_off = Convert.ToDouble(txt_010_239off.Text);
                            break;
                        case 4:
                            lum_off = Convert.ToDouble(txt_010_231off.Text);
                            break;
                        case 5:
                            lum_off = Convert.ToDouble(txt_010_223off.Text);
                            break;
                        case 6:
                            lum_off = Convert.ToDouble(txt_010_215off.Text);
                            break;
                        case 7:
                            lum_off = Convert.ToDouble(txt_010_207off.Text);
                            break;
                        case 8:
                            lum_off = Convert.ToDouble(txt_010_191off.Text);
                            break;
                        case 9:
                            lum_off = Convert.ToDouble(txt_010_175off.Text);
                            break;
                        case 10:
                            lum_off = Convert.ToDouble(txt_010_159off.Text);
                            break;
                        case 11:
                            lum_off = Convert.ToDouble(txt_010_143off.Text);
                            break;
                        case 12:
                            lum_off = Convert.ToDouble(txt_010_127off.Text) * Convert.ToDouble(txt_010_127.Text) / 100;
                            break;
                        case 13:
                            lum_off = Convert.ToDouble(txt_010_111off.Text) * Convert.ToDouble(txt_010_111.Text) / 100;
                            break;
                        case 14:
                            lum_off = Convert.ToDouble(txt_010_95off.Text) * Convert.ToDouble(txt_010_95.Text) / 100;
                            break;
                        case 15:
                            lum_off = Convert.ToDouble(txt_010_79off.Text) * Convert.ToDouble(txt_010_79.Text) / 100;
                            break;
                        case 16:
                            lum_off = Convert.ToDouble(txt_010_63off.Text) * Convert.ToDouble(txt_010_63.Text) / 100;
                            break;
                        case 17:
                            lum_off = Convert.ToDouble(txt_010_47off.Text) * Convert.ToDouble(txt_010_47.Text) / 100;
                            break;
                        case 18:
                            lum_off = Convert.ToDouble(txt_010_39off.Text) * Convert.ToDouble(txt_010_39.Text) / 100;
                            break;
                        case 19:
                            lum_off = Convert.ToDouble(txt_010_31off.Text) * Convert.ToDouble(txt_010_31.Text) / 100;
                            break;
                        case 20:
                            lum_off = Convert.ToDouble(txt_010_23off.Text) * Convert.ToDouble(txt_010_23.Text) / 100;
                            break;
                        case 21:
                            lum_off = Convert.ToDouble(txt_010_15off.Text) * Convert.ToDouble(txt_010_15.Text) / 100;
                            break;
                        case 22:
                            lum_off = Convert.ToDouble(txt_010_11off.Text) * Convert.ToDouble(txt_010_11.Text) / 100;
                            break;
                        case 23:
                            {
                                lum_off = Convert.ToDouble(txt_010_7off.Text) * Convert.ToDouble(txt_010_7.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                            }
                            break;
                    }
                    frmHelp.numPatternR.Value = Parttern_RM6D010[index];
                    frmHelp.numPatternG.Value = Parttern_RM6D010[index];
                    frmHelp.numPatternB.Value = Parttern_RM6D010[index];
                    Application.DoEvents();
                    frmHelp.OLED_Show_Click(frmHelp.btnPatternW, e);//写入Pattern参数
                    Thread.Sleep(10); //1秒=1000毫秒，
                    T20.Enabled = true;
                    flag1 = 1;
                    flag2 = 1;
                    flag3 = 1;
                }
            }
            else
            {
                Lr_t = CaSDKObj.R_y * ((frmHelp.CASDK_y - CaSDKObj.G_y) * (CaSDKObj.B_x - frmHelp.CASDK_x) + (frmHelp.CASDK_x - CaSDKObj.G_x) * (frmHelp.CASDK_y - CaSDKObj.B_y)) / CaSDKObj.B_y / ((frmHelp.CASDK_y - CaSDKObj.G_y) * (frmHelp.CASDK_x - CaSDKObj.R_x) + (frmHelp.CASDK_x - CaSDKObj.G_x) * (CaSDKObj.R_y - frmHelp.CASDK_y));
                Lb_t = 1.0;
                Lg_t = CaSDKObj.G_y * ((frmHelp.CASDK_y - CaSDKObj.R_y) * (CaSDKObj.B_x - frmHelp.CASDK_x) + (frmHelp.CASDK_x - CaSDKObj.R_x) * (frmHelp.CASDK_y - CaSDKObj.B_y)) / CaSDKObj.B_y / ((frmHelp.CASDK_y - CaSDKObj.R_y) * (frmHelp.CASDK_x - CaSDKObj.G_x) + (frmHelp.CASDK_x - CaSDKObj.R_x) * (CaSDKObj.G_y - frmHelp.CASDK_y));
                lumr = frmHelp.CASDK_LUM * Lr_t / (Lr_t + Lg_t + Lb_t);
                lumg = frmHelp.CASDK_LUM * Lg_t / (Lr_t + Lg_t + Lb_t);
                lumb = frmHelp.CASDK_LUM * Lb_t / (Lr_t + Lg_t + Lb_t);

                switch (index)
                {
                    case 0:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R255.Value = rm010_R255.Value + step_h;
                                    else rm010_R255.Value = rm010_R255.Value - step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R255.Value = rm010_R255.Value + step_l;
                                    else rm010_R255.Value = rm010_R255.Value - step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G255.Value = rm010_G255.Value + step_h;
                                    else rm010_G255.Value = rm010_G255.Value - step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G255.Value = rm010_G255.Value + step_l;
                                    else rm010_G255.Value = rm010_G255.Value - step_l;
                                }
                                adjust_Gnum++;

                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B255.Value = rm010_B255.Value + step_h;
                                    else rm010_B255.Value = rm010_B255.Value - step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B255.Value = rm010_B255.Value + step_l;
                                    else rm010_B255.Value = rm010_B255.Value - step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[24], Convert.ToUInt16(rm010_R255.Value), GAMMAs.RM010_Gamma_g[24], Convert.ToUInt16(rm010_G255.Value), GAMMAs.RM010_Gamma_b[24], Convert.ToUInt16(rm010_B255.Value));
                        }
                        break;
                    case 1:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R247.Value = rm010_R247.Value + step_h;
                                    else rm010_R247.Value = rm010_R247.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R247.Value < rm010_R255.Value)
                                        rm010_R247.Value = rm010_R255.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R247.Value = rm010_R247.Value + step_l;
                                    else rm010_R247.Value = rm010_R247.Value - step_l;
                                    if (rm010_R247.Value < rm010_R255.Value)
                                        rm010_R247.Value = rm010_R255.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G247.Value = rm010_G247.Value + step_h;
                                    else rm010_G247.Value = rm010_G247.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G247.Value < rm010_G255.Value)
                                        rm010_G247.Value = rm010_G255.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G247.Value = rm010_G247.Value + step_l;
                                    else rm010_G247.Value = rm010_G247.Value - step_l;
                                    if (rm010_G247.Value < rm010_G255.Value)
                                        rm010_G247.Value = rm010_G255.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B247.Value = rm010_B247.Value + step_h;
                                    else rm010_B247.Value = rm010_B247.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B247.Value < rm010_B255.Value)
                                        rm010_B247.Value = rm010_B255.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B247.Value = rm010_B247.Value + step_l;
                                    else rm010_B247.Value = rm010_B247.Value - step_l;
                                    if (rm010_B247.Value < rm010_B255.Value)
                                        rm010_B247.Value = rm010_B255.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[23], Convert.ToUInt16(rm010_R247.Value), GAMMAs.RM010_Gamma_g[23], Convert.ToUInt16(rm010_G247.Value), GAMMAs.RM010_Gamma_b[23], Convert.ToUInt16(rm010_B247.Value));
                        }
                        break;
                    case 2:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R243.Value = rm010_R243.Value + step_h;
                                    else rm010_R243.Value = rm010_R243.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R243.Value < rm010_R247.Value)
                                        rm010_R243.Value = rm010_R247.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R243.Value = rm010_R243.Value + step_l;
                                    else rm010_R243.Value = rm010_R243.Value - step_l;
                                    if (rm010_R243.Value < rm010_R247.Value)
                                        rm010_R243.Value = rm010_R247.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G243.Value = rm010_G243.Value + step_h;
                                    else rm010_G243.Value = rm010_G243.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G243.Value < rm010_G247.Value)
                                        rm010_G243.Value = rm010_G247.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G243.Value = rm010_G243.Value + step_l;
                                    else rm010_G243.Value = rm010_G243.Value - step_l;
                                    if (rm010_G243.Value < rm010_G247.Value)
                                        rm010_G243.Value = rm010_G247.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B243.Value = rm010_B243.Value + step_h;
                                    else rm010_B243.Value = rm010_B243.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B243.Value < rm010_B247.Value)
                                        rm010_B243.Value = rm010_B247.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B243.Value = rm010_B243.Value + step_l;
                                    else rm010_B243.Value = rm010_B243.Value - step_l;
                                    if (rm010_B243.Value < rm010_B247.Value)
                                        rm010_B243.Value = rm010_B247.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[22], Convert.ToUInt16(rm010_R243.Value), GAMMAs.RM010_Gamma_g[22], Convert.ToUInt16(rm010_G243.Value), GAMMAs.RM010_Gamma_b[22], Convert.ToUInt16(rm010_B243.Value));
                        }
                        break;
                    case 3:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R239.Value = rm010_R239.Value + step_h;
                                    else rm010_R239.Value = rm010_R239.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R239.Value < rm010_R243.Value)
                                        rm010_R239.Value = rm010_R243.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R239.Value = rm010_R239.Value + step_l;
                                    else rm010_R239.Value = rm010_R239.Value - step_l;
                                    if (rm010_R239.Value < rm010_R243.Value)
                                        rm010_R239.Value = rm010_R243.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G239.Value = rm010_G239.Value + step_h;
                                    else rm010_G239.Value = rm010_G239.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G239.Value < rm010_G243.Value)
                                        rm010_G239.Value = rm010_G243.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G239.Value = rm010_G239.Value + step_l;
                                    else rm010_G239.Value = rm010_G239.Value - step_l;
                                    if (rm010_G239.Value < rm010_G243.Value)
                                        rm010_G239.Value = rm010_G243.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B239.Value = rm010_B239.Value + step_h;
                                    else rm010_B239.Value = rm010_B239.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B239.Value < rm010_B243.Value)
                                        rm010_B239.Value = rm010_B243.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B239.Value = rm010_B239.Value + step_l;
                                    else rm010_B239.Value = rm010_B239.Value - step_l;
                                    if (rm010_B239.Value < rm010_B243.Value)
                                        rm010_B239.Value = rm010_B243.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[21], Convert.ToUInt16(rm010_R239.Value), GAMMAs.RM010_Gamma_g[21], Convert.ToUInt16(rm010_G239.Value), GAMMAs.RM010_Gamma_b[21], Convert.ToUInt16(rm010_B239.Value));
                        }
                        break;
                    case 4:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R231.Value = rm010_R231.Value + step_h;
                                    else rm010_R231.Value = rm010_R231.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R231.Value < rm010_R239.Value)
                                        rm010_R231.Value = rm010_R239.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R231.Value = rm010_R231.Value + step_l;
                                    else rm010_R231.Value = rm010_R231.Value - step_l;
                                    if (rm010_R231.Value < rm010_R239.Value)
                                        rm010_R231.Value = rm010_R239.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G231.Value = rm010_G231.Value + step_h;
                                    else rm010_G231.Value = rm010_G231.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G231.Value < rm010_G239.Value)
                                        rm010_G231.Value = rm010_G239.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G231.Value = rm010_G231.Value + step_l;
                                    else rm010_G231.Value = rm010_G231.Value - step_l;
                                    if (rm010_G231.Value < rm010_G239.Value)
                                        rm010_G231.Value = rm010_G239.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B231.Value = rm010_B231.Value + step_h;
                                    else rm010_B231.Value = rm010_B231.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B231.Value < rm010_B239.Value)
                                        rm010_B231.Value = rm010_B239.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B231.Value = rm010_B231.Value + step_l;
                                    else rm010_B231.Value = rm010_B231.Value - step_l;
                                    if (rm010_B231.Value < rm010_B239.Value)
                                        rm010_B231.Value = rm010_B239.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[20], Convert.ToUInt16(rm010_R231.Value), GAMMAs.RM010_Gamma_g[20], Convert.ToUInt16(rm010_G231.Value), GAMMAs.RM010_Gamma_b[20], Convert.ToUInt16(rm010_B231.Value));
                        }
                        break;
                    case 5:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R223.Value = rm010_R223.Value + step_h;
                                    else rm010_R223.Value = rm010_R223.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R223.Value < rm010_R231.Value)
                                        rm010_R223.Value = rm010_R231.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R223.Value = rm010_R223.Value + step_l;
                                    else rm010_R223.Value = rm010_R223.Value - step_l;
                                    if (rm010_R223.Value < rm010_R231.Value)
                                        rm010_R223.Value = rm010_R231.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G223.Value = rm010_G223.Value + step_h;
                                    else rm010_G223.Value = rm010_G223.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G223.Value < rm010_G231.Value)
                                        rm010_G223.Value = rm010_G231.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G223.Value = rm010_G223.Value + step_l;
                                    else rm010_G223.Value = rm010_G223.Value - step_l;
                                    if (rm010_G223.Value < rm010_G231.Value)
                                        rm010_G223.Value = rm010_G231.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B223.Value = rm010_B223.Value + step_h;
                                    else rm010_B223.Value = rm010_B223.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B223.Value < rm010_B231.Value)
                                        rm010_B223.Value = rm010_B231.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B223.Value = rm010_B223.Value + step_l;
                                    else rm010_B223.Value = rm010_B223.Value - step_l;
                                    if (rm010_B223.Value < rm010_B231.Value)
                                        rm010_B223.Value = rm010_B231.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[19], Convert.ToUInt16(rm010_R223.Value), GAMMAs.RM010_Gamma_g[19], Convert.ToUInt16(rm010_G223.Value), GAMMAs.RM010_Gamma_b[19], Convert.ToUInt16(rm010_B223.Value));
                        }
                        break;
                    case 6:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R215.Value = rm010_R215.Value + step_h;
                                    else rm010_R215.Value = rm010_R215.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R215.Value < rm010_R223.Value)
                                        rm010_R215.Value = rm010_R223.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R215.Value = rm010_R215.Value + step_l;
                                    else rm010_R215.Value = rm010_R215.Value - step_l;
                                    if (rm010_R215.Value < rm010_R223.Value)
                                        rm010_R215.Value = rm010_R223.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G215.Value = rm010_G215.Value + step_h;
                                    else rm010_G215.Value = rm010_G215.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G215.Value < rm010_G223.Value)
                                        rm010_G215.Value = rm010_G223.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G215.Value = rm010_G215.Value + step_l;
                                    else rm010_G215.Value = rm010_G215.Value - step_l;
                                    if (rm010_G215.Value < rm010_G223.Value)
                                        rm010_G215.Value = rm010_G223.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B215.Value = rm010_B215.Value + step_h;
                                    else rm010_B215.Value = rm010_B215.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B215.Value < rm010_B223.Value)
                                        rm010_B215.Value = rm010_B223.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B215.Value = rm010_B215.Value + step_l;
                                    else rm010_B215.Value = rm010_B215.Value - step_l;
                                    if (rm010_B215.Value < rm010_B223.Value)
                                        rm010_B215.Value = rm010_B223.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[18], Convert.ToUInt16(rm010_R215.Value), GAMMAs.RM010_Gamma_g[18], Convert.ToUInt16(rm010_G215.Value), GAMMAs.RM010_Gamma_b[18], Convert.ToUInt16(rm010_B215.Value));
                        }
                        break;
                    case 7:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R207.Value = rm010_R207.Value + step_h;
                                    else rm010_R207.Value = rm010_R207.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R207.Value < rm010_R215.Value)
                                        rm010_R207.Value = rm010_R215.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R207.Value = rm010_R207.Value + step_l;
                                    else rm010_R207.Value = rm010_R207.Value - step_l;
                                    if (rm010_R207.Value < rm010_R215.Value)
                                        rm010_R207.Value = rm010_R215.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G207.Value = rm010_G207.Value + step_h;
                                    else rm010_G207.Value = rm010_G207.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G207.Value < rm010_G215.Value)
                                        rm010_G207.Value = rm010_G215.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G207.Value = rm010_G207.Value + step_l;
                                    else rm010_G207.Value = rm010_G207.Value - step_l;
                                    if (rm010_G207.Value < rm010_G215.Value)
                                        rm010_G207.Value = rm010_G215.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B207.Value = rm010_B207.Value + step_h;
                                    else rm010_B207.Value = rm010_B207.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B207.Value < rm010_B215.Value)
                                        rm010_B207.Value = rm010_B215.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B207.Value = rm010_B207.Value + step_l;
                                    else rm010_B207.Value = rm010_B207.Value - step_l;
                                    if (rm010_B207.Value < rm010_B215.Value)
                                        rm010_B207.Value = rm010_B215.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[17], Convert.ToUInt16(rm010_R207.Value), GAMMAs.RM010_Gamma_g[17], Convert.ToUInt16(rm010_G207.Value), GAMMAs.RM010_Gamma_b[17], Convert.ToUInt16(rm010_B207.Value));
                        }
                        break;
                    case 8:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R191.Value = rm010_R191.Value + step_h;
                                    else rm010_R191.Value = rm010_R191.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R191.Value < rm010_R207.Value)
                                        rm010_R191.Value = rm010_R207.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R191.Value = rm010_R191.Value + step_l;
                                    else rm010_R191.Value = rm010_R191.Value - step_l;
                                    if (rm010_R191.Value < rm010_R207.Value)
                                        rm010_R191.Value = rm010_R207.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G191.Value = rm010_G191.Value + step_h;
                                    else rm010_G191.Value = rm010_G191.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G191.Value < rm010_G207.Value)
                                        rm010_G191.Value = rm010_G207.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G191.Value = rm010_G191.Value + step_l;
                                    else rm010_G191.Value = rm010_G191.Value - step_l;
                                    if (rm010_G191.Value < rm010_G207.Value)
                                        rm010_G191.Value = rm010_G207.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B191.Value = rm010_B191.Value + step_h;
                                    else rm010_B191.Value = rm010_B191.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B191.Value < rm010_B207.Value)
                                        rm010_B191.Value = rm010_B207.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B191.Value = rm010_B191.Value + step_l;
                                    else rm010_B191.Value = rm010_B191.Value - step_l;
                                    if (rm010_B191.Value < rm010_B207.Value)
                                        rm010_B191.Value = rm010_B207.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[16], Convert.ToUInt16(rm010_R191.Value), GAMMAs.RM010_Gamma_g[16], Convert.ToUInt16(rm010_G191.Value), GAMMAs.RM010_Gamma_b[16], Convert.ToUInt16(rm010_B191.Value));
                        }
                        break;
                    case 9:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R175.Value = rm010_R175.Value + step_h;
                                    else rm010_R175.Value = rm010_R175.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R175.Value < rm010_R191.Value)
                                        rm010_R175.Value = rm010_R191.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R175.Value = rm010_R175.Value + step_l;
                                    else rm010_R175.Value = rm010_R175.Value - step_l;
                                    if (rm010_R175.Value < rm010_R191.Value)
                                        rm010_R175.Value = rm010_R191.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G175.Value = rm010_G175.Value + step_h;
                                    else rm010_G175.Value = rm010_G175.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G175.Value < rm010_G191.Value)
                                        rm010_G175.Value = rm010_G191.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G175.Value = rm010_G175.Value + step_l;
                                    else rm010_G175.Value = rm010_G175.Value - step_l;
                                    if (rm010_G175.Value < rm010_G191.Value)
                                        rm010_G175.Value = rm010_G191.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B175.Value = rm010_B175.Value + step_h;
                                    else rm010_B175.Value = rm010_B175.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B175.Value < rm010_B191.Value)
                                        rm010_B175.Value = rm010_B191.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B175.Value = rm010_B175.Value + step_l;
                                    else rm010_B175.Value = rm010_B175.Value - step_l;
                                    if (rm010_B175.Value < rm010_B191.Value)
                                        rm010_B175.Value = rm010_B191.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[15], Convert.ToUInt16(rm010_R175.Value), GAMMAs.RM010_Gamma_g[15], Convert.ToUInt16(rm010_G175.Value), GAMMAs.RM010_Gamma_b[15], Convert.ToUInt16(rm010_B175.Value));
                        }
                        break;
                    case 10:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R159.Value = rm010_R159.Value + step_h;
                                    else rm010_R159.Value = rm010_R159.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R159.Value < rm010_R175.Value)
                                        rm010_R159.Value = rm010_R175.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R159.Value = rm010_R159.Value + step_l;
                                    else rm010_R159.Value = rm010_R159.Value - step_l;
                                    if (rm010_R159.Value < rm010_R175.Value)
                                        rm010_R159.Value = rm010_R175.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G159.Value = rm010_G159.Value + step_h;
                                    else rm010_G159.Value = rm010_G159.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G159.Value < rm010_G175.Value)
                                        rm010_G159.Value = rm010_G175.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G159.Value = rm010_G159.Value + step_l;
                                    else rm010_G159.Value = rm010_G159.Value - step_l;
                                    if (rm010_G159.Value < rm010_G175.Value)
                                        rm010_G159.Value = rm010_G175.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B159.Value = rm010_B159.Value + step_h;
                                    else rm010_B159.Value = rm010_B159.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B159.Value < rm010_B175.Value)
                                        rm010_B159.Value = rm010_B175.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B159.Value = rm010_B159.Value + step_l;
                                    else rm010_B159.Value = rm010_B159.Value - step_l;
                                    if (rm010_B159.Value < rm010_B175.Value)
                                        rm010_B159.Value = rm010_B175.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[14], Convert.ToUInt16(rm010_R159.Value), GAMMAs.RM010_Gamma_g[14], Convert.ToUInt16(rm010_G159.Value), GAMMAs.RM010_Gamma_b[14], Convert.ToUInt16(rm010_B159.Value));
                        }
                        break;
                    case 11:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R143.Value = rm010_R143.Value + step_h;
                                    else rm010_R143.Value = rm010_R143.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R143.Value < rm010_R159.Value)
                                        rm010_R143.Value = rm010_R159.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R143.Value = rm010_R143.Value + step_l;
                                    else rm010_R143.Value = rm010_R143.Value - step_l;
                                    if (rm010_R143.Value < rm010_R159.Value)
                                        rm010_R143.Value = rm010_R159.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G143.Value = rm010_G143.Value + step_h;
                                    else rm010_G143.Value = rm010_G143.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G143.Value < rm010_G159.Value)
                                        rm010_G143.Value = rm010_G159.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G143.Value = rm010_G143.Value + step_l;
                                    else rm010_G143.Value = rm010_G143.Value - step_l;
                                    if (rm010_G143.Value < rm010_G159.Value)
                                        rm010_G143.Value = rm010_G159.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B143.Value = rm010_B143.Value + step_h;
                                    else rm010_B143.Value = rm010_B143.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B143.Value < rm010_B159.Value)
                                        rm010_B143.Value = rm010_B159.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B143.Value = rm010_B143.Value + step_l;
                                    else rm010_B143.Value = rm010_B143.Value - step_l;
                                    if (rm010_B143.Value < rm010_B159.Value)
                                        rm010_B143.Value = rm010_B159.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[13], Convert.ToUInt16(rm010_R143.Value), GAMMAs.RM010_Gamma_g[13], Convert.ToUInt16(rm010_G143.Value), GAMMAs.RM010_Gamma_b[13], Convert.ToUInt16(rm010_B143.Value));
                        }
                        break;
                    case 12:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R127.Value = rm010_R127.Value + step_h;
                                    else rm010_R127.Value = rm010_R127.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R127.Value < rm010_R143.Value)
                                        rm010_R127.Value = rm010_R143.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R127.Value = rm010_R127.Value + step_l;
                                    else rm010_R127.Value = rm010_R127.Value - step_l;
                                    if (rm010_R127.Value < rm010_R143.Value)
                                        rm010_R127.Value = rm010_R143.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G127.Value = rm010_G127.Value + step_h;
                                    else rm010_G127.Value = rm010_G127.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G127.Value < rm010_G143.Value)
                                        rm010_G127.Value += rm010_G143.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G127.Value = rm010_G127.Value + step_l;
                                    else rm010_G127.Value = rm010_G127.Value - step_l;
                                    if (rm010_G127.Value < rm010_G143.Value)
                                        rm010_G127.Value = rm010_G143.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B127.Value = rm010_B127.Value + step_h;
                                    else rm010_B127.Value = rm010_B127.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B127.Value < rm010_B143.Value)
                                        rm010_B127.Value = rm010_B143.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B127.Value = rm010_B127.Value + step_l;
                                    else rm010_B127.Value = rm010_B127.Value - step_l;
                                    if (rm010_B127.Value < rm010_B143.Value)
                                        rm010_B127.Value = rm010_B143.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[12], Convert.ToUInt16(rm010_R127.Value), GAMMAs.RM010_Gamma_g[12], Convert.ToUInt16(rm010_G127.Value), GAMMAs.RM010_Gamma_b[12], Convert.ToUInt16(rm010_B127.Value));
                        }
                        break;
                    case 13:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R111.Value = rm010_R111.Value + step_h;
                                    else rm010_R111.Value = rm010_R111.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R111.Value < rm010_R127.Value)
                                        rm010_R111.Value = rm010_R127.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R111.Value = rm010_R111.Value + step_l;
                                    else rm010_R111.Value = rm010_R111.Value - step_l;
                                    if (rm010_R111.Value < rm010_R127.Value)
                                        rm010_R111.Value = rm010_R127.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G111.Value = rm010_G111.Value + step_h;
                                    else rm010_G111.Value = rm010_G111.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G111.Value < rm010_G127.Value)
                                        rm010_G111.Value = rm010_G127.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G111.Value = rm010_G111.Value + step_l;
                                    else rm010_G111.Value = rm010_G111.Value - step_l;
                                    if (rm010_G111.Value < rm010_G127.Value)
                                        rm010_G111.Value = rm010_G127.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B111.Value = rm010_B111.Value + step_h;
                                    else rm010_B111.Value = rm010_B111.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B111.Value < rm010_B127.Value)
                                        rm010_B111.Value = rm010_B127.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B111.Value = rm010_B111.Value + step_l;
                                    else rm010_B111.Value = rm010_B111.Value - step_l;
                                    if (rm010_B111.Value < rm010_B127.Value)
                                        rm010_B111.Value = rm010_B127.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[11], Convert.ToUInt16(rm010_R111.Value), GAMMAs.RM010_Gamma_g[11], Convert.ToUInt16(rm010_G111.Value), GAMMAs.RM010_Gamma_b[11], Convert.ToUInt16(rm010_B111.Value));
                        }
                        break;
                    case 14:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R95.Value = rm010_R95.Value + step_h;
                                    else rm010_R95.Value = rm010_R95.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R95.Value < rm010_R111.Value)
                                        rm010_R95.Value = rm010_R111.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R95.Value = rm010_R95.Value + step_l;
                                    else rm010_R95.Value = rm010_R95.Value - step_l;
                                    if (rm010_R95.Value < rm010_R111.Value)
                                        rm010_R95.Value = rm010_R111.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G95.Value = rm010_G95.Value + step_h;
                                    else rm010_G95.Value = rm010_G95.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G95.Value < rm010_G111.Value)
                                        rm010_G95.Value = rm010_G111.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G95.Value = rm010_G95.Value + step_l;
                                    else rm010_G95.Value = rm010_G95.Value - step_l;
                                    if (rm010_G95.Value < rm010_G111.Value)
                                        rm010_G95.Value = rm010_G111.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B95.Value = rm010_B95.Value + step_h;
                                    else rm010_B95.Value = rm010_B95.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B95.Value < rm010_B111.Value)
                                        rm010_B95.Value = rm010_B111.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B95.Value = rm010_B95.Value + step_l;
                                    else rm010_B95.Value = rm010_B95.Value - step_l;
                                    if (rm010_B95.Value < rm010_B111.Value)
                                        rm010_B95.Value = rm010_B111.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[10], Convert.ToUInt16(rm010_R95.Value), GAMMAs.RM010_Gamma_g[10], Convert.ToUInt16(rm010_G95.Value), GAMMAs.RM010_Gamma_b[10], Convert.ToUInt16(rm010_B95.Value));
                        }
                        break;
                    case 15:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R79.Value = rm010_R79.Value + step_h;
                                    else rm010_R79.Value = rm010_R79.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R79.Value < rm010_R95.Value)
                                        rm010_R79.Value = rm010_R95.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R79.Value = rm010_R79.Value + step_l;
                                    else rm010_R79.Value = rm010_R79.Value - step_l;
                                    if (rm010_R79.Value < rm010_R95.Value)
                                        rm010_R79.Value = rm010_R95.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G79.Value = rm010_G79.Value + step_h;
                                    else rm010_G79.Value = rm010_G79.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G79.Value < rm010_G95.Value)
                                        rm010_G79.Value = rm010_G95.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G79.Value = rm010_G79.Value + step_l;
                                    else rm010_G79.Value = rm010_G79.Value - step_l;
                                    if (rm010_G79.Value < rm010_G95.Value)
                                        rm010_G79.Value = rm010_G95.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B79.Value = rm010_B79.Value + step_h;
                                    else rm010_B79.Value = rm010_B79.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B79.Value < rm010_B95.Value)
                                        rm010_B79.Value = rm010_B95.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B79.Value = rm010_B79.Value + step_l;
                                    else rm010_B79.Value = rm010_B79.Value - step_l;
                                    if (rm010_B79.Value < rm010_B95.Value)
                                        rm010_B79.Value = rm010_B95.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[9], Convert.ToUInt16(rm010_R79.Value), GAMMAs.RM010_Gamma_g[9], Convert.ToUInt16(rm010_G79.Value), GAMMAs.RM010_Gamma_b[9], Convert.ToUInt16(rm010_B79.Value));
                        }
                        break;
                    case 16:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R63.Value = rm010_R63.Value + step_h;
                                    else rm010_R63.Value = rm010_R63.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R63.Value < rm010_R79.Value)
                                        rm010_R63.Value = rm010_R79.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R63.Value = rm010_R63.Value + step_l;
                                    else rm010_R63.Value = rm010_R63.Value - step_l;
                                    if (rm010_R63.Value < rm010_R79.Value)
                                        rm010_R63.Value = rm010_R79.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G63.Value = rm010_G63.Value + step_h;
                                    else rm010_G63.Value = rm010_G63.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G63.Value < rm010_G79.Value)
                                        rm010_G63.Value = rm010_G79.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G63.Value = rm010_G63.Value + step_l;
                                    else rm010_G63.Value = rm010_G63.Value - step_l;
                                    if (rm010_G63.Value < rm010_G79.Value)
                                        rm010_G63.Value = rm010_G79.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B63.Value = rm010_B63.Value + step_h;
                                    else rm010_B63.Value = rm010_B63.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B63.Value < rm010_B79.Value)
                                        rm010_B63.Value = rm010_B79.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B63.Value = rm010_B63.Value + step_l;
                                    else rm010_B63.Value = rm010_B63.Value - step_l;
                                    if (rm010_B63.Value < rm010_B79.Value)
                                        rm010_B63.Value = rm010_B79.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[8], Convert.ToUInt16(rm010_R63.Value), GAMMAs.RM010_Gamma_g[8], Convert.ToUInt16(rm010_G63.Value), GAMMAs.RM010_Gamma_b[8], Convert.ToUInt16(rm010_B63.Value));
                        }
                        break;
                    case 17:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R47.Value = rm010_R47.Value + step_h;
                                    else rm010_R47.Value = rm010_R47.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R47.Value < rm010_R63.Value)
                                        rm010_R47.Value = rm010_R63.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R47.Value = rm010_R47.Value + step_l;
                                    else rm010_R47.Value = rm010_R47.Value - step_l;
                                    if (rm010_R47.Value < rm010_R63.Value)
                                        rm010_R47.Value = rm010_R63.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G47.Value = rm010_G47.Value + step_h;
                                    else rm010_G47.Value = rm010_G47.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G47.Value < rm010_G63.Value)
                                        rm010_G47.Value = rm010_G63.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G47.Value = rm010_G47.Value + step_l;
                                    else rm010_G47.Value = rm010_G47.Value - step_l;
                                    if (rm010_G47.Value < rm010_G63.Value)
                                        rm010_G47.Value = rm010_G63.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B47.Value = rm010_B47.Value + step_h;
                                    else rm010_B47.Value = rm010_B47.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B47.Value < rm010_B63.Value)
                                        rm010_B47.Value = rm010_B63.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B47.Value = rm010_B47.Value + step_l;
                                    else rm010_B47.Value = rm010_B47.Value - step_l;
                                    if (rm010_B47.Value < rm010_B63.Value)
                                        rm010_B47.Value = rm010_B63.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[7], Convert.ToUInt16(rm010_R47.Value), GAMMAs.RM010_Gamma_g[7], Convert.ToUInt16(rm010_G47.Value), GAMMAs.RM010_Gamma_b[7], Convert.ToUInt16(rm010_B47.Value));
                        }
                        break;
                    case 18:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R39.Value = rm010_R39.Value + step_h;
                                    else rm010_R39.Value = rm010_R39.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R39.Value < rm010_R47.Value)
                                        rm010_R39.Value = rm010_R47.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R39.Value = rm010_R39.Value + step_l;
                                    else rm010_R39.Value = rm010_R39.Value - step_l;
                                    if (rm010_R39.Value < rm010_R47.Value)
                                        rm010_R39.Value = rm010_R47.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G39.Value = rm010_G39.Value + step_h;
                                    else rm010_G39.Value = rm010_G39.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G39.Value < rm010_G47.Value)
                                        rm010_G39.Value = rm010_G47.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G39.Value = rm010_G39.Value + step_l;
                                    else rm010_G39.Value = rm010_G39.Value - step_l;
                                    if (rm010_G39.Value < rm010_G47.Value)
                                        rm010_G39.Value = rm010_G47.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B39.Value = rm010_B39.Value + step_h;
                                    else rm010_B39.Value = rm010_B39.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B39.Value < rm010_B47.Value)
                                        rm010_B39.Value = rm010_B47.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B39.Value = rm010_B39.Value + step_l;
                                    else rm010_B39.Value = rm010_B39.Value - step_l;
                                    if (rm010_B39.Value < rm010_B47.Value)
                                        rm010_B39.Value = rm010_B47.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[6], Convert.ToUInt16(rm010_R39.Value), GAMMAs.RM010_Gamma_g[6], Convert.ToUInt16(rm010_G39.Value), GAMMAs.RM010_Gamma_b[6], Convert.ToUInt16(rm010_B39.Value));
                        }
                        break;
                    case 19:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R31.Value = rm010_R31.Value + step_h;
                                    else rm010_R31.Value = rm010_R31.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R31.Value < rm010_R39.Value)
                                        rm010_R31.Value = rm010_R39.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R31.Value = rm010_R31.Value + step_l;
                                    else rm010_R31.Value = rm010_R31.Value - step_l;
                                    if (rm010_R31.Value < rm010_R39.Value)
                                        rm010_R31.Value = rm010_R39.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G31.Value = rm010_G31.Value + step_h;
                                    else rm010_G31.Value = rm010_G31.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G31.Value < rm010_G39.Value)
                                        rm010_G31.Value = rm010_G39.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G31.Value = rm010_G31.Value + step_l;
                                    else rm010_G31.Value = rm010_G31.Value - step_l;
                                    if (rm010_G31.Value < rm010_G39.Value)
                                        rm010_G31.Value = rm010_G39.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B31.Value = rm010_B31.Value + step_h;
                                    else rm010_B31.Value = rm010_B31.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B31.Value < rm010_B39.Value)
                                        rm010_B31.Value = rm010_B39.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B31.Value = rm010_B31.Value + step_l;
                                    else rm010_B31.Value = rm010_B31.Value - step_l;
                                    if (rm010_B31.Value < rm010_B39.Value)
                                        rm010_B31.Value = rm010_B39.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[5], Convert.ToUInt16(rm010_R31.Value), GAMMAs.RM010_Gamma_g[5], Convert.ToUInt16(rm010_G31.Value), GAMMAs.RM010_Gamma_b[5], Convert.ToUInt16(rm010_B31.Value));
                        }
                        break;
                    case 20:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R23.Value = rm010_R23.Value + step_h;
                                    else rm010_R23.Value = rm010_R23.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R23.Value < rm010_R31.Value)
                                        rm010_R23.Value = rm010_R31.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R23.Value = rm010_R23.Value + step_l;
                                    else rm010_R23.Value = rm010_R23.Value - step_l;
                                    if (rm010_R23.Value < rm010_R31.Value)
                                        rm010_R23.Value = rm010_R31.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G23.Value = rm010_G23.Value + step_h;
                                    else rm010_G23.Value = rm010_G23.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G23.Value < rm010_G31.Value)
                                        rm010_G23.Value = rm010_G31.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G23.Value = rm010_G23.Value + step_l;
                                    else rm010_G23.Value = rm010_G23.Value - step_l;
                                    if (rm010_G23.Value < rm010_G31.Value)
                                        rm010_G23.Value = rm010_G31.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B23.Value = rm010_B23.Value + step_h;
                                    else rm010_B23.Value = rm010_B23.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B23.Value < rm010_B31.Value)
                                        rm010_B23.Value = rm010_B31.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B23.Value = rm010_B23.Value + step_l;
                                    else rm010_B23.Value = rm010_B23.Value - step_l;
                                    if (rm010_B23.Value < rm010_B31.Value)
                                        rm010_B23.Value = rm010_B31.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[4], Convert.ToUInt16(rm010_R23.Value), GAMMAs.RM010_Gamma_g[4], Convert.ToUInt16(rm010_G23.Value), GAMMAs.RM010_Gamma_b[4], Convert.ToUInt16(rm010_B23.Value));
                        }
                        break;
                    case 21:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R15.Value = rm010_R15.Value + step_h;
                                    else rm010_R15.Value = rm010_R15.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R15.Value < rm010_R23.Value)
                                        rm010_R15.Value = rm010_R23.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R15.Value = rm010_R15.Value + step_l;
                                    else rm010_R15.Value = rm010_R15.Value - step_l;
                                    if (rm010_R15.Value < rm010_R23.Value)
                                        rm010_R15.Value = rm010_R23.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G15.Value = rm010_G15.Value + step_h;
                                    else rm010_G15.Value = rm010_G15.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G15.Value < rm010_G23.Value)
                                        rm010_G15.Value = rm010_G23.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G15.Value = rm010_G15.Value + step_l;
                                    else rm010_G15.Value = rm010_G15.Value - step_l;
                                    if (rm010_G15.Value < rm010_G23.Value)
                                        rm010_G15.Value = rm010_G23.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B15.Value = rm010_B15.Value + step_h;
                                    else rm010_B15.Value = rm010_B15.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B15.Value < rm010_B23.Value)
                                        rm010_B15.Value = rm010_B23.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B15.Value = rm010_B15.Value + step_l;
                                    else rm010_B15.Value = rm010_B15.Value - step_l;
                                    if (rm010_B15.Value < rm010_B23.Value)
                                        rm010_B15.Value = rm010_B23.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[3], Convert.ToUInt16(rm010_R15.Value), GAMMAs.RM010_Gamma_g[3], Convert.ToUInt16(rm010_G15.Value), GAMMAs.RM010_Gamma_b[3], Convert.ToUInt16(rm010_B15.Value));
                        }
                        break;
                    case 22:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R11.Value = rm010_R11.Value + step_h;
                                    else rm010_R11.Value = rm010_R11.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R11.Value < rm010_R15.Value)
                                        rm010_R11.Value = rm010_R15.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R11.Value = rm010_R11.Value + step_l;
                                    else rm010_R11.Value = rm010_R11.Value - step_l;
                                    if (rm010_R11.Value < rm010_R15.Value)
                                        rm010_R11.Value = rm010_R15.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G11.Value = rm010_G11.Value + step_h;
                                    else rm010_G11.Value = rm010_G11.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G11.Value < rm010_G15.Value)
                                        rm010_G11.Value = rm010_G15.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G11.Value = rm010_G11.Value + step_l;
                                    else rm010_G11.Value = rm010_G11.Value - step_l;
                                    if (rm010_G11.Value < rm010_G15.Value)
                                        rm010_G11.Value = rm010_G15.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B11.Value = rm010_B11.Value + step_h;
                                    else rm010_B11.Value = rm010_B11.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B11.Value < rm010_B15.Value)
                                        rm010_B11.Value = rm010_B15.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B11.Value = rm010_B11.Value + step_l;
                                    else rm010_B11.Value = rm010_B11.Value - step_l;
                                    if (rm010_B11.Value < rm010_B15.Value)
                                        rm010_B11.Value = rm010_B15.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[2], Convert.ToUInt16(rm010_R11.Value), GAMMAs.RM010_Gamma_g[2], Convert.ToUInt16(rm010_G11.Value), GAMMAs.RM010_Gamma_b[2], Convert.ToUInt16(rm010_B11.Value));
                        }
                        break;
                    case 23:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R7.Value = rm010_R7.Value + step_h;
                                    else rm010_R7.Value = rm010_R7.Value - step_h;
                                    adjust_Rnum = 0;
                                    if (rm010_R7.Value < rm010_R11.Value)
                                        rm010_R7.Value = rm010_R11.Value + step_h;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        rm010_R7.Value = rm010_R7.Value + step_l;
                                    else rm010_R7.Value = rm010_R7.Value - step_l;
                                    if (rm010_R7.Value < rm010_R11.Value)
                                        rm010_R7.Value = rm010_R11.Value + step_l;
                                }
                                adjust_Rnum++;
                            }

                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G7.Value = rm010_G7.Value + step_h;
                                    else rm010_G7.Value = rm010_G7.Value - step_h;
                                    adjust_Gnum = 0;
                                    if (rm010_G7.Value < rm010_G11.Value)
                                        rm010_G7.Value = rm010_G11.Value + step_h;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        rm010_G7.Value = rm010_G7.Value + step_l;
                                    else rm010_G7.Value = rm010_G7.Value - step_l;
                                    if (rm010_G7.Value < rm010_G11.Value)
                                        rm010_G7.Value = rm010_G11.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B7.Value = rm010_B7.Value + step_h;
                                    else rm010_B7.Value = rm010_B7.Value - step_h;
                                    adjust_Bnum = 0;
                                    if (rm010_B7.Value < rm010_B11.Value)
                                        rm010_B7.Value = rm010_B11.Value + step_h;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        rm010_B7.Value = rm010_B7.Value + step_l;
                                    else rm010_B7.Value = rm010_B7.Value - step_l;
                                    if (rm010_B7.Value < rm010_B11.Value)
                                        rm010_B7.Value = rm010_B11.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                            frmHelp.auto_gamma_write(GAMMAs.RM010_Gamma_r[1], Convert.ToUInt16(rm010_R7.Value), GAMMAs.RM010_Gamma_g[1], Convert.ToUInt16(rm010_G7.Value), GAMMAs.RM010_Gamma_b[1], Convert.ToUInt16(rm010_B7.Value));
                        }
                        break;
                }
            }
        }
        private void RM6D010_Gamma_Load(object sender, EventArgs e)
        {

        }
    }
}
